package com.nowc.week.w106_c;

import java.io.*;
import java.math.BigInteger;

public class b {

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        int T = Integer.parseInt(br.readLine());
        while (T-- > 0) {
            solve();
        }
        out.flush();
        out.close();
        br.close();
    }

    static void solve() throws IOException {
        String[] s = br.readLine().split(" ");
        String n = s[0];
        long k = Long.parseLong(s[1]);

        BigInteger cur = new BigInteger(n);
        if (f(cur.toString())) {
            out.println(cur + " 0");
            return;
        }
        for (int i = 1; i <= k; i++) {
            String rev = new StringBuilder(cur.toString()).reverse().toString();
            BigInteger revs = new BigInteger(rev);
            cur = cur.add(revs);
            if (f(cur.toString())) {
                out.println(cur + " " + i);
                return;
            }
        }
        out.println(cur + " " + -1);
    }

    static boolean f(String s) {
        int l = 0, r = s.length() - 1;
        while (l < r) {
            if (s.charAt(l++) != s.charAt(r--)) return false;
        }
        return true;
    }
}
